using System.Design;
using System.ComponentModel;
using System;
using System.Collections;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
		
namespace Microsoft.Samples
{
	/// <summary>
	/// Summary description for SolidClockDesigner.
	/// </summary>
	public class SolidClockDesigner : ControlDesigner
	{
		private DesignerVerbCollection verbs;
		SolidClock solidClock;
		
		///     Returns the design-time verbs supported by the component associated with
		///     the customizer. The verbs returned by this method are typically displayed
		///     in a right-click menu by the design-time environment. The return value may
		///     be null if the component has no design-time verbs. When a user selects one
		///     of the verbs, the performVerb() method is invoked with the the
		///     corresponding DesignerVerb object.
		///     NOTE: A design-time environment will typically provide a "Properties..."
		///     entry on a component's right-click menu. The getVerbs() method should
		///     therefore not include such an entry in the returned list of verbs.
		public override DesignerVerbCollection Verbs 
		{
			get 
			{
				if (verbs == null) 
				{
					verbs = new DesignerVerbCollection();
					verbs.Add(new DesignerVerb(("Increase Outer Ring Thickness"), new EventHandler(this.OnIncreaseOuterRingThickness)));
					verbs.Add(new DesignerVerb(("Decrease Outer Ring Thickness"), new EventHandler(this.OnDecreaseOuterRingThickness)));
					verbs.Add(new DesignerVerb(("Increase Intra Arc Padding"), new EventHandler(this.OnIncreaseIntraArcPadding)));
					verbs.Add(new DesignerVerb(("Decrease Intra Arc Padding"), new EventHandler(this.OnDecreaseIntraArcPadding)));
				}

				return verbs;
			}
		}

		public override void Initialize(IComponent component) 
		{
			base.Initialize(component);
			solidClock = Control as SolidClock;
			if (solidClock == null) 
			{
				throw new Exception("The control this SolidClockDesigner is attatched to is not a SolidClock.");
			}
		}

		///      Called in response to the verb to increase the thickness of the outer ring.  
		private void OnIncreaseOuterRingThickness(object sender, EventArgs e) 
		{
			IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
			if (host != null) 
			{
				DesignerTransaction t = null;
				try 
				{
					t = host.CreateTransaction(solidClock.Name + " increase outer arc thickness");

					PropertyDescriptor prop;
					prop = TypeDescriptor.GetProperties(solidClock)["OuterArcThickness"];
					prop.SetValue(solidClock, solidClock.OuterArcThickness + 1);
				}
				finally 
				{
					if (t != null)
						t.Commit();
				}
			}
		}

		///      Called in response to the verb to decrease the thickness of the outer ring.  
		private void OnDecreaseOuterRingThickness(object sender, EventArgs e) 
		{
			IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
			if (host != null) 
			{
				DesignerTransaction t = null;
				try 
				{
					t = host.CreateTransaction(solidClock.Name + " decrease outer arc thickness");

					PropertyDescriptor prop;
					prop = TypeDescriptor.GetProperties(solidClock)["OuterArcThickness"];
					prop.SetValue(solidClock, solidClock.OuterArcThickness - 1);
				}
				finally 
				{
					if (t != null)
						t.Commit();
				}
			}
		}

		///      Called in response to the verb to increase the thickness of the outer ring.  
		private void OnIncreaseIntraArcPadding(object sender, EventArgs e) 
		{
			IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
			if (host != null) 
			{
				DesignerTransaction t = null;
				try 
				{
					t = host.CreateTransaction(solidClock.Name + " increase arc padding");

					PropertyDescriptor prop;
					prop = TypeDescriptor.GetProperties(solidClock)["IntraArcPadding"];
					prop.SetValue(solidClock, solidClock.IntraArcPadding + 1);
				}
				finally 
				{
					if (t != null)
						t.Commit();
				}
			}
		}

		///      Called in response to the verb to increase the thickness of the outer ring.  
		private void OnDecreaseIntraArcPadding(object sender, EventArgs e) 
		{
			IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
			if (host != null) 
			{
				DesignerTransaction t = null;
				try 
				{
					t = host.CreateTransaction(solidClock.Name + " decrease arc padding");

					PropertyDescriptor prop;
					prop = TypeDescriptor.GetProperties(solidClock)["IntraArcPadding"];
					prop.SetValue(solidClock, solidClock.IntraArcPadding - 1);
				}
				finally 
				{
					if (t != null)
						t.Commit();
				}
			}
		}
	}
}
